package com.mashibing.serviceverificationcode.controller;

import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.response.NumberCodeResponse;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @title: NumberCodeController
 * @Author Z先森
 * @Date: 2022/9/19 16:17
 * @Version 1.0
 */
@RestController
@Slf4j
public class NumberCodeController {
    /**
     * 获取验证码
     * @param size 验证码大小
     * @return ResponseResult
     */
    @GetMapping("/numberCode/{size}")
    public ResponseResult numberCode(@PathVariable int size){
        int numberCode = (int) ((Math.random() * 9+1)*(Math.pow(10,size-1)));
        log.info(String.valueOf(numberCode));
        NumberCodeResponse response = new NumberCodeResponse();
        response.setNumberCode(numberCode);
        return ResponseResult.success(response);
    }


    public static void main(String[] args) {
        double v = (Math.random() * 9+1)*(Math.pow(10,5));
        int num = (int) v;
        System.out.println(num);
    }
}
